﻿using System;
using System.Collections.Generic;
using System.Web.UI;
using SmartMenu.Classes;
using SmartMenu.Controllers;
using visinia.SmartEngine;
using visinia.SmartEngine.Modules;

public partial class Modules_General_SmartMenu_SmartMenu : WebModule
{
    protected override void WebModuleRender(HtmlTextWriter output)
    {
        int menuid = 0;
        if (Int32.TryParse((string)Settings["Menu"], out menuid))
        {
            MenuInfo menuInfo = MenuController.GetMenu(menuid);
            if (menuInfo != null)
            {
                List<string> text = new List<string>();
                List<string> links = new List<string>();
                foreach (MenuItemInfo menuItemInfo in MenuItemController.GetMenuItems(menuInfo.MenuId))
                {
                    if (!menuItemInfo.Visible)
                        continue;
                    string title = menuItemInfo.Title;
                    string url = menuItemInfo.Url;
                    text.Add(title);
                    if (url.StartsWith("http://"))
                        links.Add(url);
                    else
                        links.Add(WebRoots.GetWebRoot + url);
                }                             
                string data = WebHelpers.GenerateBulletedListHyperLinks(text.ToArray(), links.ToArray(), Request.RawUrl);
                output.Write(data);
            }
        }
    }
}